home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / hypercrd / hc2_x / tcprogud.sit / TC Prog Guide / card_47191.txt < prev    next >
Text File  |  1991-02-27  |  948b  |  26 lines

  1. -- card: 47191 from stack: in
  2. -- bmap block id: 0
  3. -- flags: 0000
  4. -- background id: 4755
  5. -- name: 
  6.  
  7.  
  8. -- part contents for background part 4
  9. ----- text -----
  10. CASTS
  11.  
  12. Explicit type conversion is performed using the cast operator.  A value is "cast" to another type by prefixing it with the desired type enclosed in parentheses.  For example, to ensure that floating-point rather than integer arithmetic is used, it may be desirable to cast an integer variable to a float in an arithmetic expression.  In this case, f is assigned the value 0 while g is assigned 0.5:
  13.  
  14.     int     a = 1,
  15.               b = 2;
  16.     float  f,g;
  17.     f = a / b;
  18.     g = (float) a / b;
  19.  
  20. The cast operator has higher precedence than arithmetic operators, so the value of 'a' is converted to a float before the division takes place.
  21.  
  22. In TC and C++ casts are often used to inform the compiler of the class of an object 
  23.  
  24. -- part contents for background part 7
  25. ----- text -----
  26. 150